<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.onlineMIS.ORM.entity.headQ.supplier.purchase.PurchaseOrder,com.onlineMIS.ORM.entity.base.BaseOrder"%>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><s:property value="formBean.order.typeS" /> <s:property
		value="formBean.order.statusS" /></title>
<%@ include file="../../../common/Style.jsp"%>

<script type="text/javascript" src="<%=request.getContextPath()%>/conf_files/js/HtmlTable.js"></script>
<script src='http://127.0.0.1:8000/CLodopfuncs.js'></script>
<script src='http://127.0.0.1:18000/CLodopfuncs.js'></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/conf_files/js/lodop/headProcureLodop.js?v=10.46"></script>
<script type="text/javascript">
var baseurl = "<%=request.getContextPath()%>";

var index = 0;

function BSkeyDown(e){

	 var ieKey = event.keyCode;

	 if (ieKey==13){
	   if (event.srcElement.id == "supplierName"){
		   searchSupplier(); 
		   event.returnValue=false;
	   } else if (event.srcElement.id =="barcodeInput"){
	       var barcodeInput =$("#barcodeInput");

	       event.returnValue=false;
	       retrieveProductByBarcode("","",barcodeInput.val(),"");

	   } else if (event.srcElement.id =="productCodeInput"){

		   event.returnValue=false;
		   
		   searchProductsProductCode(index);
 	   }else if (event.srcElement.id =="factoryCodeInput"){

		   event.returnValue=false;
		   
		   searchProductsFactoryCode(index);
 	   } else if (event.srcElement.id.substring(0,8)=="quantity"){
 		   $("#productCodeInput").focus();
	   } else
		   event.returnValue=false; 
	 }  else if (ieKey==8){
		    if((event.srcElement.tagName.toLowerCase() == "input" && event.srcElement.readOnly != true) || event.srcElement.tagName.toLowerCase() == "textarea"){
		        event.returnValue = true; 
		    } else
		    	event.returnValue = false;
	 } 
} 

document.onkeydown = BSkeyDown; 

/**
 * user input the product code and press enter
 */
function searchProductsProductCode(index_trigger){

	var productCode = $("#productCodeInput").val();

	if (validateProductCodeInput(productCode)){
	    var params= "formBean.productBarcode.product.productCode=" + productCode + "&formBean.indexPage=" + index_trigger + "&formBean.fromSrc=1"; 
	    
	    var url = encodeURI(encodeURI("productJSPAction!scanByProductCodeHeadq?" +params));
		
	    window.open(url,'新窗口','height=600, width=680, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');    
	}
}

/**
 * user input the product code and press enter
 */
function searchProductsFactoryCode(index_trigger){

	var factoryCode = $("#factoryCodeInput").val();
	
	if (validateFactoryCodeInput(factoryCode)){
	    var params= "formBean.productBarcode.product.factoryCode=" + factoryCode + "&formBean.indexPage=" + index_trigger + "&formBean.fromSrc=1"; 
	    
	    var url = encodeURI(encodeURI("productJSPAction!scanByProductCodeHeadq?" +params));
		
	    window.open(url,'新窗口','height=600, width=680, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');    
	}
}

/**
 * to validate the product code input
 */
function validateFactoryCodeInput(factoryCode){
	if (factoryCode.length <= 1){
       $.messager.alert('错误', "输入的厂家货号太短", 'warning');
       return false;
	}
	return true;
}

/**
 * to validate the product code input
 */
function validateProductCodeInput(productCode){
	if (productCode.length <= 1){
       $.messager.alert('错误', "输入的货号太短", 'warning');
       return false;
	}
	return true;
}

/**
 * just override the function
 */
function validateRowInputFromChild(currentBarcode){
	return true;
}

/**
 * to validate whether the product is selected or not
 */
function validateRowInput(currentBarcode){
	if (currentBarcode.length != BARCODE_LENGTH){
		$.messager.alert('失败警告',currentBarcode + " 不是一个正常条形.请重新输入.", 'error');
		return false;
    } else {
		for (var i = 0; i < index; i++){
			var barcodeInput =  $("#barcode" +i);

			if (currentBarcode == barcodeInput.val()){				
				
				var currentQ = $("#quantity" +i).val();
				var numberPerHand = 0;			
				
				// 齐手或单件
				var fullOrSingle = $("#fullOrSingle").val();
				
				var fullType = '';
				
				if (fullOrSingle == 0){
					numberPerHand = $("#numPerHand" +i).val();
					fullType = '齐手';
				}else {
					numberPerHand = 1;
					fullType = '单件';
				}

				$("#quantity" + i).val( parseInt(currentQ) + parseInt(numberPerHand));
				
				var afterNum = parseInt(currentQ) + parseInt(numberPerHand);
				
				var nowRow = i+1;
				
				 $.messager.show({
		                title:'提示',
		                msg:'注意：在第【' + nowRow +'】行,已有该货品 '+ '<br>' 
		                + '条码：【' +  currentBarcode +'】' + '<br>'
		                + '扫码前数量：【' + currentQ + '】' + '<br>'
		                + '添加类型：【' + fullType + '】' + '<br>'
		                + '扫码后数量：【' + afterNum + '】',
		                showType:'show',
		                style:{
		                	background: '#FFC0CB',
		                	right:'',
		                	height: '160px',
		                	timeout:3000,
		                    top:document.body.scrollTop+document.documentElement.scrollTop,
		                    bottom:''
		                }
		            });
				 
				 $("#row"+i).addClass("hight")
				
				calculateTotal();
				
				$("#barcodeInput").val("");
				$("#productCodeInput").val("");
				return false;
			}
		}
    }
	return true;
}

function retrieveProductByBarcode(index_trigger, suffix ,currentBarcode, fromSrc){
   //if (validateRowInput(currentBarcode)){
	var supplierId = $("#supplierId").val();	
	var orderType = $("#orderType").val();
	
    var params= "formBean.pb.barcode=" + currentBarcode + "&formBean.supplier.supplierId=" + supplierId + "&formBean.indexPage=" + index +"&formBean.order.type=" + orderType+"&formBean.fromSrc=" + fromSrc ; 

    $.post("supplierPurchaseJSON!scanByBarcodePurchaseOrder",params, backProcess,"json");
  // }
}

function backProcess(returnValue){

	
	var returnCode = returnValue.returnCode;
	
	if (returnCode == SUCCESS){
		var data = returnValue.returnValue;
		var pop = data.pop;
		
		var preIndex = data.index;
		var orderType = data.orderType;
	
		addNewRow(pop);
		
		calculateTotal();
		
		var where = data.where;
		if (where == 1){
			var indexB= index - 1;
			$("#productCodeInput").val("");
			$("#productCodeInput").focus();
		} else {
			$("#barcodeInput").val("");
			$("#barcodeInput").focus();
		}
		$("#factoryCodeInput").val("");
	} else {
		$.messager.alert('错误', returnValue.message, 'error');
		$("#barcodeInput").val("");
		$("#barcodeInput").focus();
	}
}


function calculateTotal(){
	 var totalQ = 0;
	 var totalRecCost = 0;
//	 var totalWholePrice = 0;
	 
	 for (var i =0; i < index; i++){
		 
		 var quantityInputs = $("#quantity" + i).val();
		 var recCostInputs = $("#recCost" + i).val();
		 //var wholeSalePriceInputs = $("#wholeSalePrice" + i).val();
		 
		 if (quantityInputs != undefined){
			 totalQ = totalQ + parseInt(quantityInputs);
		 } 

		 if (quantityInputs != undefined && recCostInputs != undefined && recCostInputs !=""){
			 var totalRecCostRow = parseInt(quantityInputs)*parseFloat(recCostInputs);
			 $("#totalRecCost" + i).val(totalRecCostRow);
			 totalRecCost += totalRecCostRow ;
		 } 
//		 if (quantityInputs != undefined && wholeSalePriceInputs != undefined && wholeSalePriceInputs !=""){
//			 totalWholePrice = totalWholePrice + parseInt(quantityInputs)*parseFloat(wholeSalePriceInputs);
//		 } 
	 }
	 
	 $("#totalQuantity").val(totalQ);
	 $("#totalRecCost").val((totalRecCost).toFixed(2));
}


function deleteRow(rowID, delIndex){

	var msg = "你确定要删除第" + (delIndex + 1) + "行 ";
	
	$("#row" + delIndex).css('background-color', '#99CC00');
	$.messager.confirm('删除货品确认', msg, function(r){
		if (r){
			$("#"+rowID).remove(); 
			
			calculateTotal(); 
		} else {
			$("#row" + delIndex).css('background-color', '');
		}
	});
	
	$("#productCodeInput").focus();
}

function addNewRow(pop){
	
	// 齐手或单件
	var fullOrSingle = $("#fullOrSingle").val();
	
	var barcode = pop.pb;
	indexB = index
    var str = "";
    str += "<tr height='22' id='row"+ indexB + "' class='excelTable' align='center'>";

    str += "<td align='center'>" + (indexB+1) +"</td>";
    str += "<td><input type='text' id='barcode"+indexB+"'  size=10 readonly value='"+barcode.barcode +"'/><input type='hidden' id='numPerHand"+indexB+"' value='"+ barcode.product.numPerHand+"'/><input type='hidden' name='formBean.order.productList["+indexB+"].pb.id' id='productId"+indexB+"' value='"+ barcode.id+"'/></td>";		 					 		
    str += "<td><input type='text' size=6 readonly value='"+barcode.product.productCode+"'/> </td>";
    str += "<td><input type='text' size=9 readonly value='"+barcode.product.productIdentity+"'/> </td>";
    str += "<td><input type='text' size=9 readonly value='"+barcode.product.factoryCode+"'/> </td>";
    str += "<td><input type='text' size=3 readonly value='"+barcode.product.year.year+"'/> </td>";	
    str += "<td><input type='text' size=3 readonly value='"+barcode.product.quarter.quarter_Name+"'/> </td>";	
    str += "<td><input type='text' size=12 readonly value='"+barcode.product.brand.brand_Name+"'/> </td>";		
    
    str += "<td><input type='text' size=12 readonly value='"+barcode.product.categoryName+"'/> </td>";   
    
	var color = barcode.color;
	var colorName = "";
	if (color != null && color != undefined && color.name!=undefined)
		colorName = color.name; 

	//产品标准成本
	var	recCost = barcode.product.recCost;
	var recCost2 = pop.recCost;
	var totalRecCost = pop.totalRecCost;
	var wholeSalePrice = pop.wholeSalePrice;
	var quantity = 0;
	var discount = 1;//默认不打折
	if(pop.discount !=1){
		discount = pop.discount.toFixed(2);
	}
	
	if (fullOrSingle == 0){
		quantity = pop.quantity;
	}else {
		quantity = 1;
	}
			
    str += "<td><input type='text' size=2 readonly value='" + colorName+"'/> </td>";	
    str += "<td><input type='text' size=2 readonly value='"+barcode.product.unit+"'/> </td>"; 
    str += "<td><input type='text' name='formBean.order.productList["+indexB+"].price'  id='price"+indexB+"' size=4 readonly value='"+barcode.product.recCost+"'/> </td>"; 
    str += "<td><input type='text' name='formBean.order.productList["+indexB+"].quantity' id='quantity"+indexB+"' value='"+quantity+"' size='2'  onchange='onQuantityChange("+indexB+");'  onfocus='this.select();'/>  </td>";
    str += "<td><input type='text' name='formBean.order.productList["+indexB+"].discount' id='discount"+indexB+"' value='"+discount+"' size='2' onchange='changeDiscount("+indexB+");' onfocus='this.select();'/>  </td>";
    str += "<td><input type='text' name='formBean.order.productList["+indexB+"].recCost' id='recCost"+indexB+"' value='"+recCost2+"' size='4' onchange='changeRecCost("+indexB+");' onfocus='this.select();'/>  </td>";
    str += "<td><input type='text' id='totalRecCost"+indexB+"' value='"+totalRecCost+"' size='4' readonly/>  </td>";
    str += "<td><input type='text' size=4 readonly value='"+(barcode.product.salesPrice).toFixed(2)+"'/> </td>";		
    str += "<td><input type='text' size=4 readonly value='"+(wholeSalePrice).toFixed(2)+"'/> </td>";
    str += "<td><img src='"+baseurl+"/conf_files/easyUI/themes/icons/img3.png' border='0' onclick='viewImgP(\"row"+indexB +"\","+indexB+")' style='cursor:pointer;'/></td>";
    str += "<td><img src='"+baseurl+"/conf_files/easyUI/themes/icons/delete2.png' border='0' onclick='deleteRow(\"row"+indexB +"\","+indexB+")' style='cursor:pointer;'/></td>";		 		
    str += "</tr>";
    
    $("#inventoryTable").append(str);

    $("#row"+ indexB).bind('keyup',onkeyup);
    
	$("#row"+ indexB).mouseover(function(){      
		$(this).addClass("over");}).mouseout(function(){    
		$(this).removeClass("over");}); 
	
	index++;
}

function validateForm(){
   	for (var i =0; i < index; i++)
   		$("#row" + i).css('background-color', '');
   	
	var error = "";
	if ($("#supplierName").val() == "" || $("#supplierId").val() == 0){
		error += "供应商名字 - 必须填<br\>";
		$("#supplierName").focus();
	}

	if ($("#counterId").combobox("getValue") == 0){
		error += "点数人员 - 必须选<br\>";
		$("#counterId").focus();
	}

	if (isNaN($("#counterId").combobox("getValue"))){
		error += "货品点数人员名称不规范,请重新点击确认货品点数人员";
		$("#counterId").focus();
	}

	if ($("#totalQuantity").val() <= 0){
		error += "必须录入数据后才能提交<br\>";
	}
	var totalDiscount = $("#totalDiscount").val();
	if (isNaN(totalDiscount) ){
		error += "优惠 - 必须是数字<br\>";
	}

	var hasChar = false;
	var hasChar_r = false;
	var invalid_barcode = false;
	for (var i =0; i < index; i++){

		var q = $("#quantity" + i).val();
		var r = $("#recCost" + i).val();
		var pbId = $("#productId" + i).val();

		if (q != undefined){
			if (isNaN(q) || q<=0){
				$("#row" + i).css('background-color', '#EE8553');
				hasChar = true;
			}
		}
		if (r != undefined){
			if (isNaN(r) || r<=0 || r=='Infinity'){
				$("#row" + i).css('background-color', '#EE8553');
				hasChar_r = true;
			}
		}

		if (pbId != undefined){
			if (isEmpty(pbId) || pbId == 0){
				$("#row" + i).css('background-color', '#EE8553');
				invalid_barcode = true;
			}
		}
	}

	if (hasChar)
		error += "数量 - 必须为大于0数字<br\>";
	if (hasChar_r)
		error += "采购进价 - 必须为大于0数字<br\>";	

	if (invalid_barcode)
		error += "条码错误 - 货品条码无法找到,请删除再从新扫描<br\>";	
	
	return error;
}

/**
 * 数量改变
 */
function onQuantityChange(index){
	var num = $("#quantity" + index).val();
	if(!isPositiveInteger(num)){
		var num = $("#quantity" + index).val(0);
		$.messager.alert('错误', "有非法字符输入，请输入正确的数量", 'warning');
	}else{		
		calculateTotal();
	}
}


/**
 * 修改进价（单价）后，修改进价折扣
 */
function changeRecCost(index){
	//产品的基础成本
	var price = $("#price" + index).val();
	var recCost = $("#recCost" + index).val();
	var disCount2 = recCost/price;
	 $("#discount" + index).val((disCount2).toFixed(2));
	if (disCount2 >1)
	    $.messager.alert('警告', '当前修改后,折扣大于1', 'warning');
	calculateTotal();	
}

/**
 * 修改进价折扣后，修改进价（单价）
 */
function changeDiscount(index){
	//产品的基础成本
	var price = $("#price" + index).val();
	var discount = $("#discount" + index).val();
	
	if (discount >1)
	    $.messager.alert('警告', '当前修改后,折扣大于1', 'warning');
	
	var recCost = price * discount;
	 $("#recCost" + index).val((recCost).toFixed(2));
	 
	 calculateTotal();
}


function deleteOrder(){
	$.messager.confirm('确认','您确认想要删除此条记录吗？',function(r){
	    if (r){	   
		   	var url = "<%=request.getContextPath()%>/action/supplierPurchaseJSON!deletePurchase";
			var params=$("#purchaseOrderForm").serialize();  
			$.post(url,params, deleteOrderBackProcess,"json");	
	    }
	});

}

function deleteOrderBackProcess(data){
	$.messager.progress('close');
    var response = data;
	var returnCode = response.returnCode;
	if (returnCode != SUCCESS)
		$.messager.alert('错误', response.message, 'error');
	else {
		$.messager.alert({
			title: '成功',
			closable: false,
			msg: '删除单据成功',
			fn: function(){
				parent.closeTab();
			}
		});
    }
}

index = parseInt("<s:property value='formBean.order.productList.size()'/>");

function saveToDraft(){
	$.messager.progress({
		title : '提示',
		text : '数据处理中，请稍后....'
	});
	calculateTotal();
	
	var error = validateForm();
	
	if (error != ""){
		$.messager.progress('close'); 
		$.messager.alert('错误', error, 'error');
	} else {

		var params = $("#purchaseOrderForm").serialize();  
		$.post("<%=request.getContextPath()%>/action/supplierPurchaseJSON!saveToDraft",params, draftOrderBKProcess,"json");
	}
}
function draftOrderBKProcess(data){
	var response = data;

	var returnCode = response.returnCode;
	var returnMsg = response.message;

	if (returnCode == SUCCESS){		
		$.messager.alert({
			title: '提示',
			msg: '成功保存草稿',
			fn: function(){
				window.location.href = 'supplierPurchaseJSP!preEditPurchase';
			}
		});
	} else {
		$.messager.progress('close'); 
        $.messager.alert('错误', returnMsg, 'error');
    }
}


/**
 * to submit the order to account
 */
function submitOrder(){
	
	calculateTotal();
	var error = validateForm();
	if (error != ""){
		$.messager.progress('close'); 
		$.messager.alert('错误', error, 'error');
	} else {
		
		var prompt = "请核对此次提交数据 ";
		
    	var supplierName = $("#supplierName").val();
    	
    	var orderType = $("#orderType").val();
    	
    	var currentAcctBalance = $("#currentAcctBalance").val();
    	
    	var totalDiscount = $("#totalDiscount").val();
    	
    	var totalQuantity = $("#totalQuantity").val();
    	
    	var totalRecCost = $("#totalRecCost").val();
    	
    	var orderTypeS = $("#orderTypeS").val();;
    	
    	var postSuccessfullyArrears;
    	
    	if(orderType == TYPE_PURCHASE){
    		postSuccessfullyArrears = Number(currentAcctBalance) + Number(totalRecCost);
    	}else if(orderType == TYPE_RETURN){
    		postSuccessfullyArrears = Number(currentAcctBalance) - Number(totalRecCost);
    	}else if(orderType == TYPE_FREE){
    		postSuccessfullyArrears = currentAcctBalance;
    	}else {
    		postSuccessfullyArrears = 0;
    	}    	
    	var commitPromptMsg = "【供应商】：" + supplierName + "<br>"
    	+ "【采购数量】：" + totalQuantity + "<br>"
    	+ "【采购类型】：" + orderTypeS + "<br>"
    	+ "【采购总价】：" + totalRecCost + "<br>"
    	+ "【当前欠款】：" + currentAcctBalance + "<br>"
    	+ "【优惠】：" + totalDiscount + "<br>"
    	+ "【过账后欠款】：" + postSuccessfullyArrears + "<br>";
	
		$.messager.confirm(prompt, commitPromptMsg, function(r){
	        if (r){
	        	var params = $("#purchaseOrderForm").serialize();  
	        	$.post("<%=request.getContextPath()%>/action/supplierPurchaseJSON!saveToComplete",params, submitOrderBKProcess,"json");	        	 	    		
	        }
	    });
		
	}
}
function submitOrderBKProcess(data){
	var response = data;

	var returnCode = response.returnCode;
	var returnMsg = response.message;
	var returnValue = response.returnValue;

	if(returnCode == SUCCESS){
		if (returnValue == TYPE_PURCHASE){					 
			 $.messager.alert({
				 	title: '采购录入提示',
					msg: returnMsg,
					fn: function(){
						window.location.href = 'supplierPurchaseJSP!preEditPurchase';
					}
				});
			
		} else if( returnValue == TYPE_RETURN){
			$.messager.alert({
				title: '采购退货提示',
				msg: returnMsg,
				fn: function(){
					window.location.href = 'supplierPurchaseJSP!preEditPurchaseReturn';
				}
			});
		}else if( returnValue == TYPE_FREE){
			$.messager.alert({
				title: '采购赠送提示',
				msg: returnMsg,
				fn: function(){
					window.location.href = 'supplierPurchaseJSP!preEditPurchaseFree';
				}
			});
		}else {
			$.messager.progress('close'); 
	        $.messager.alert('错误', returnMsg, 'error');
	    }
	}else {
		$.messager.progress('close'); 
        $.messager.alert('错误', returnMsg, 'error');
    }
	
	
	
	
}
function importFile(){
	 window.open("supplierPurchaseJSP!preUploadFile",'新窗口','height=200, width=300, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');    
}

function retrieveProductByExcel(products){

    if (products.length != 0){
    	for (var i = 0 ; i < products.length; i++){
    		var p = products[i];
   		
	        addNewRow(p);
    	}
    	
    	calculateTotal();
    }
    $.messager.alert('完成', "完成导入，请检查", 'info');

}

function downloadOrder(){
	$.messager.confirm('确认','在下载单据前保证你已经保存了修改',function(r){
	    if (r){	   
	    	var url = "<%=request.getContextPath()%>/action/supplierPurchaseJSP!downloadPurchase";
	    	document.purchaseOrderForm.action = url;
	    	document.purchaseOrderForm.submit();
	    }
	});
}
$(document).ready(function(){
	$("#supplierName").focus();
	parent.$.messager.progress('close'); 
	jQuery.excel('excelTable');
	$("#org_table tr").mouseover(function(){      
		$(this).addClass("over");}).mouseout(function(){    
		$(this).removeClass("over");}); 
});

/**
 * 查看图片详情
 */
function viewImgP(rowID, delIndex){
	
	var barcode = $("#barcode" + delIndex).val();
	viewImg(barcode);
}
</script>

</head>
<body>

	<s:form action="/action/inventoryOrder!previewOrder" method="POST"
		name="purchaseOrderForm" id="purchaseOrderForm" theme="simple"
		enctype="multipart/form-data">
		<s:hidden name="formBean.order.id" id="orderId" />
		<s:hidden name="formBean.order.type" id="orderType" />
		<s:hidden name="formBean.order.typeHQS" id="orderTypeS" />
		<table cellpadding="0" border="0" cellspacing="0" style="width: 98%"
			align="center" class="OuterTable">
			<tr class="title">
				<td colspan="7"><s:if test="formBean.order.type == 0">
						<font style="color: mediumseagreen; font-size: 16px;"><s:property
								value="formBean.order.typeS" /> </font>
					</s:if> <s:elseif test="formBean.order.type == 1">
						<font style="color: #EEB4B4; font-size: 16px;"><s:property
								value="formBean.order.typeS" /> </font>
					</s:elseif> <s:elseif test="formBean.order.type == 2">
						<font style="color: orange; font-size: 16px;"><s:property
								value="formBean.order.typeS" /> </font>
					</s:elseif> <s:else>
						<s:property value="formBean.order.typeS" />
					</s:else> <s:property value="formBean.order.statusS" /></td>
			</tr>

			<tr height="10">
				<td colspan="14"><hr /></td>
			</tr>

			<tr>
				<td colspan="7">
					<table cellpadding="0" cellspacing="0" style="width: 100%"
						border="0"  class="OuterTable">
						<tr align="left"  class="PBAOuterTableTitale">
							<th width="50">&nbsp;</th>
							<th width="80" align="left"><%@ include
									file="../SupplierInput.jsp"%></th>
							<th  width="80">货品点数&nbsp; :&nbsp;<s:select
									name="formBean.order.orderCounter.user_id"
									data-options="prompt:'请选择点数人员'" cssClass="easyui-combobox"
									style="width:150px;text-align: center" id="counterId"
									list="uiBean.users" listKey="user_id" listValue="name"
									headerKey="0" headerValue="" />
							</th>
							<th width="80">
							<s:select name="formBean.fullOrSingle" id="fullOrSingle"   list="#{'0':'齐手','1':'单件'}" listKey="key" listValue="value" style="width:105px;text-align: center" cssClass="easyui-combobox" data-options="editable:false" >
						   </s:select>
							</th>
							<th  width="80" align="right">	总部库房：<s:select
									cssClass="easyui-combobox"
									style="width:150px;text-align: center"
									name="formBean.order.store.id" id="storeId"
									list="uiBean.stores" listKey="id" listValue="name"
									data-options="editable:false" /></th>
							<th  width="30" align="left"></th>

							<th  width="80" align="left">订单号&nbsp;:&nbsp;<s:property
									value="formBean.order.id" />
							</th>
						</tr>
					</table>

					<table  id="org_table" cellpadding="0" cellspacing="0" style="width: 100%"
						border="0">
						<tr class="
						    <s:if test="formBean.order.type == 0">
							    procureTableTop
						    </s:if>
						    <s:elseif test="formBean.order.type == 1">
							    returnProcureTableTop
							</s:elseif>
							<s:elseif test="formBean.order.type == 2">		
							    freeProcureTableTop
							</s:elseif>					
							" align="left">
								<th>&nbsp;</th>
								<th colspan="6"></th>
								<th colspan="5" align="left"></th>
								<th colspan="8"></th>
							</tr>
							<tr class="
							    <s:if test="formBean.order.type == 0">
								    procureTableTop
							    </s:if>
							    <s:elseif test="formBean.order.type == 1">
								    returnProcureTableTop
								</s:elseif>
								<s:elseif test="formBean.order.type == 2">		
								    freeProcureTableTop
								</s:elseif>										
							" height="22">
							<th style="width: 4%">&nbsp;</th>
							<th style="width: 7%">条型码</th>
							<th style="width: 5%">产品货号</th>
							<th style="width: 5%">公司货号</th>
							<th style="width: 4%">厂家货号</th>
							<th style="width: 4%">年份</th>
							<th style="width: 4%">季度</th>
							<th style="width: 7%">产品品牌</th>
							<th style="width: 7%">货品类别</th>
							<th style="width: 4%">颜色</th>
							<th style="width: 5%">单位</th>
							<th style="width: 5%">默认进价</th>
							<th style="width: 5%">数量</th>
							<th style="width: 5%">折扣</th>
							<th style="width: 5%">进价(单价)</th>
							<th style="width: 5%">进价(总价)</th>
							<th style="width: 5%">千禧吊牌价(单价)</th>
							<th style="width:6%">批发价(单价)</th>
							<th style="width: 3%">图片</th>
							<th style="width: 3%"></th>
							
						</tr>


						<tbody id="inventoryTable">
							<s:iterator value="formBean.order.productList" status="st"
								id="orderProduct">
								<tr id="row<s:property value="#st.index"/>"
									class="PBAOuterTableTitale" align="center">
									<td align="center"><s:property value="#st.index +1" /></td>
									<td><input type="text"
										id="barcode<s:property value="#st.index"/>"
										value="<s:property value="#orderProduct.pb.barcode"/>" size=10
										readonly /> <input type="hidden"
										name="formBean.order.productList[<s:property value="#st.index"/>].pb.id"
										id="productId<s:property value="#st.index"/>"
										value="<s:property value="#orderProduct.pb.id"/>" /></td>
									<td><input type="text" size=6 readonly
										value='<s:property value="#orderProduct.pb.product.productCode"/>' />
										<input type="hidden"
										id="numPerHand<s:property value="#st.index"/>"
										value='<s:property value="#orderProduct.pb.product.productIdentity" />' /></td>
									<td><input type="text" size=6 readonly
										value='<s:property value="#orderProduct.pb.product.factoryCode"/>' />
										<input type="hidden"
										id="factoryCode<s:property value="#st.index"/>"
										value='<s:property value="#orderProduct.pb.product.productIdentity" />' /></td>
									<td><input type="text" size=9 readonly
										value='<s:property value="#orderProduct.pb.product.productCode"/>' /></td>
									<td><input type="text" size=3 readonly
										value='<s:property value="#orderProduct.pb.product.year.year" />' /></td>
									<td><input type="text" size=3 readonly
										value='<s:property
											value="#orderProduct.pb.product.quarter.quarter_Name" />'></td>
									<td><input type="text" size=11 readonly
										value='<s:property
											value="#orderProduct.pb.product.brand.brand_Name" />'></td>

									<td><input type="text" size=11 readonly
										value='<s:property value="#orderProduct.pb.product.categoryName"/>'></td>
									<td><input type="text" size=2 readonly
										value='<s:property value="#orderProduct.pb.color.name" />'></td>
									<td><input type="text" size=2 readonly
										value='<s:property value="#orderProduct.pb.product.unit" />'></td>
									<td><input type="text" size=4 readonly
									    id="price<s:property value="#st.index"/>"
									    name="formBean.order.productList[<s:property value="#st.index"/>].price"
										value='<s:property value="#orderProduct.price" />'></td>
									<td><input type="text"
										name="formBean.order.productList[<s:property value="#st.index"/>].quantity"
										id="quantity<s:property value="#st.index"/>" size='2'
										onchange="onQuantityChange(<s:property value="#st.index"/>);" onfocus="this.select();"
										value="<s:property value="#orderProduct.quantity"/>" /></td>
									<td><input type="text"
										name="formBean.order.productList[<s:property value="#st.index"/>].discount"
										onchange="changeDiscount(<s:property value="#st.index"/>);"
										id="discount<s:property value="#st.index"/>" size='2'
										onfocus="this.select();"
										value="<s:property value="#orderProduct.discount"/>" /></td>	
									<td><input type="text"
										name="formBean.order.productList[<s:property value="#st.index"/>].recCost"
										id="recCost<s:property value="#st.index"/>" size='4'
										onchange="changeRecCost(<s:property value="#st.index"/>);"
										onfocus="this.select();"
										value="<s:property value="#orderProduct.recCost"/>" /></td>
									<td><input type="text"
										id="totalRecCost<s:property value="#st.index"/>" size='4'
										value="<s:property value="#orderProduct.totalRecCost"/>"
										readonly /></td>
									<td><input type="text" size=4 readonly
										value='<s:text name="format.totalPrice">
											<s:param value="#orderProduct.pb.product.salesPrice" />
										</s:text>' /></td>
									<td><input type="text" size=4 readonly
										value='<s:text name="format.totalPrice">
											<s:param value="#orderProduct.wholeSalePrice" />
										</s:text>' /></td>
									
									<td><div id="viewIcon0" style="display:block"><img src="<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/img3.png" border="0" onclick="viewImgP('row<s:property value="#st.index"/>',<s:property value="#st.index"/>);" style="cursor:pointer;"/></div></td>
									<td><div id="delIcon0" style="display: block">
											<img
												src="<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/delete2.png"
												border="0"
												onclick="deleteRow('row<s:property value="#st.index"/>',<s:property value="#st.index"/>);"
												style="cursor: pointer;" />
										</div></td>
									
								</tr>
							</s:iterator>
						</tbody>
						<tr height="10" align="center">
							<td><s:property value="#st.index +1" /></td>
							<td><input type="text" id="barcodeInput" size="10" /></td>
							<td><input type="text" value="" id="productCodeInput" size="6" /></td>
							<td></td>
							<td><input type="text" value="" id="factoryCodeInput" size="9" /></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>		
							<td></td>	
						</tr>
						
						
						<tr class="
						    <s:if test="formBean.order.type == 0">
							    procureTableTop
						    </s:if>
						    <s:elseif test="formBean.order.type == 1">
							    returnProcureTableTop
							</s:elseif>
							<s:elseif test="formBean.order.type == 2">		
							    freeProcureTableTop
							</s:elseif>									
						
						 " height="22" align="center">
							<td align="center">总计</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td><s:textfield name="formBean.order.totalQuantity"
									id="totalQuantity" readonly="true" size='2' /></td>
							<td></td>
							<td></td>
							<td><s:textfield name="formBean.order.totalRecCost"
									id="totalRecCost" size='4' readonly="true" /></td>
							<td>&nbsp;</td>
							
							<td>&nbsp;</td>
							<td colspan="4">&nbsp;</td>
						</tr>

						<tr height="10">
							<td colspan="18" align="left"></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="27" align="center">优惠:</td>
							<td colspan="2"><s:textfield cssClass="easyui-textbox"
									name="formBean.order.totalDiscount" id="totalDiscount" /></td>
							<td colspan="3"></td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td colspan="7">&nbsp;</td>
						</tr>
						<tr height="10">
							<td colspan="18" align="left"></td>
						</tr>
						<tr height="10" class="InnerTableContent">
							<td align="center">备注:</td>
							<td colspan="19"><textarea class="easyui-textbox" data-options="prompt:'请输入采购备注信息'"
									style="width: 500px" name="formBean.order.comment" id="comment"
									rows="1" cols="80"><s:property value="formBean.order.comment" /></textarea></td>
						</tr>
						<tr height="10">
							<td colspan="18" align="left"></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="27" align="center">操作:</td>
							<td colspan="18">
								<a id="btn1" href="#" class="easyui-linkbutton c2" data-options="iconCls:'icon-database'" onclick="importFile();">导入文件</a>
								<a id="btn2" href="#" class="easyui-linkbutton c6" data-options="iconCls:'icon-ok'" onclick="saveToDraft();">存入草稿</a>
								<a id="btn3" href="#" class="easyui-linkbutton c6" data-options="iconCls:'icon-save'" onclick="submitOrder();">单据提交</a>								
								<a id="btn2" href="#" class="easyui-linkbutton c7" data-options="iconCls:'icon-sum'" onclick="calculateTotal();">重新计算</a>
								 <s:if test="formBean.canDownload">
								 <a href="javascript:void(0)" id="mb1" class="easyui-menubutton" data-options="iconCls:'icon-redo',menu:'#mm',plain:false">打印操作</a>
								 <div id="mm" style="width: 150px;">
									<div id="btn3" data-options="iconCls:'icon-print'" onclick="printOrder(false);">打印单据</div>
									<div id="btn3" data-options="iconCls:'icon-print'" onclick="printOrder(true);">打印预览</div>		
								 </div>		
								 			    
								<a id="btn5" href="#" class="easyui-linkbutton c6" data-options="iconCls:'icon-database'" onclick="downloadOrder();">下载单据</a>
								<a id="btn2" href="#" class="easyui-linkbutton c6" data-options="iconCls:'icon-add'" onclick="copyOrder();">复制单据</a> 
								</s:if>
								<s:if test="formBean.canDelete">
									<a id="btn4" href="#" class="easyui-linkbutton c3" data-options="iconCls:'icon-no'" onclick="deleteOrder();">删除单据</a>
								</s:if>
								
							</td>
						</tr>
						
					</table>
				</td>
			</tr>
			<tr height="10">
				<td colspan="7"><s:fielderror /></td>
			</tr>
		</table>
	</s:form>
</body>
</html>